package com.crm.system.controller.knowledgeitem;

import com.crm.common.model.DataResponse;
import com.crm.common.model.DhPageInfo;
import com.crm.common.model.DhResponse;
import com.crm.common.model.Enum.ResponseCodeEnum;
import com.crm.common.model.Enum.StatusCodeEnum;
import com.crm.model.entity.knowledgeitem.KnowledgeSection;
import com.crm.model.qo.knowledgeitem.KnowledgeSectionQO;
import com.crm.model.vo.knowledgeitem.KnowledgeSectionVO;
import com.crm.system.service.knowledgeitem.KnowledgeSectionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @Description: 知识章节
 * @Author lixq-f
 * @Date 2021/5/7
 * @Version V1.0
 **/
@RequestMapping("/knowledgeSection")
@RestController
public class KnowledgeSectionController {

    @Autowired
    private KnowledgeSectionService sectionService;


    @PostMapping("/addKnSection")
    public DataResponse addKnSection(@Validated @RequestBody KnowledgeSectionQO sectionQO) {
        return new DhResponse(ResponseCodeEnum.OK.getResponseCode(), sectionService.insert(sectionQO));
    }


    /**
     * @Description: 获取章节
     * @Param: [itemId, pageIndex, pageSize]
     * @Return: com.crm.common.model.DataResponse
     * @Author: lixq-f
     * @Date: 2021/5/7
    **/
    @PostMapping("/selectKnSectionList")
    public DataResponse selectKnSectionList(@RequestParam("itemId") String itemId,
                                            @RequestParam(value = "pageIndex", required = false, defaultValue = "1") Integer pageIndex,
                                            @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize) {
        DhPageInfo<KnowledgeSectionVO> dhPageInfo = sectionService.selectListByKnItemId(itemId, pageIndex, pageSize);
        return new DhResponse(ResponseCodeEnum.OK.getResponseCode(), dhPageInfo);
    }

    @PostMapping("/updateKnSection")
    public DataResponse updateKnSection(@Validated @RequestBody KnowledgeSectionQO sectionQO) {
        return new DhResponse(ResponseCodeEnum.OK.getResponseCode(), sectionService.update(sectionQO));
    }


    @GetMapping("/delKnSectionById/{sectionId}")
    public DataResponse delKnSectionById(@PathVariable("sectionId") String sectionId) {
        return new DhResponse(ResponseCodeEnum.OK.getResponseCode(),
                sectionService.deleteById(sectionId,
                        (short) StatusCodeEnum.DELETE_CODE.getState()));
    }



    @GetMapping("/selectSectionByKey/{sectionId}")
    public DataResponse selectSectionByKey(@PathVariable("sectionId") String sectionId){
        return new DhResponse(ResponseCodeEnum.OK.getResponseCode(),
                sectionService.selectKnSectionByKey(sectionId));
    }



}
